﻿<!DOCTYPE html> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>SOSOMap_TestLocate</title> 
<style type="text/css"> 
body, button, input, select, textarea {
font: 12px/16px Verdana, Helvetica, Arial, sans-serif;
}
</style> 
<script charset="utf-8" src="http://api.map.soso.com/v1.0/main.js"></script> 
<script> 
var geolocation,map,marker = null;
function init(){
	center = new soso.maps.LatLng(39.916527,116.397128);
	map = new soso.maps.Map(document.getElementById('container'),{
		center: center,
		zoomLevel: 13
	});
}
//检索IP地理信息（另外可以指定IP地址定位，还有区号、地理坐标）
function ipLocate(){
	geolocation = new soso.maps.Geolocation();
	geolocation.position({}, function(results, status){
		var city = document.getElementById("city");
		if (status == soso.maps.GeolocationStatus.OK){
			map.moveTo(results.latLng);
			city.style.display = 'inline';
			city.innerHTML = '所在位置: ' + results.name;
			if (marker != null){
				marker.setMap(null);
			}
			marker = new soso.maps.Marker({
				map: map,
				position:results.latLng
			});
		}
		else{
			alert("检索没有结果，原因: " + status);
		}
	});
}
</script> 
</head> 
<body onload="init()"> 
<div style="width:580px;height:300px" id="container"></div> 
<input value="定位" type="button" onclick="ipLocate();">
<span style="height:30px;display:none" id="city"></span>
</body>
</html> 